package com.hackerrank.contests.july13.challenges.hackerranknumber;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Solution {
	private static int numBits(int N) {
		int c = 0;
		while(N > 0) {
			c++;
			N >>= 1;
		}
		return c;
	}
	private static int numDigs(int N) {
		int c = 0;
		while(N > 0) {
			c++;
			N /= 10;
		}
		return c;
	}
	private static long LCM(long a, long b) {
		return a * b / GCF(a, b);
	}
	private static long GCF(long a, long b) {
		return GCFmm(Math.min(a, b), Math.max(a, b));
	}
	private static long GCFmm(long m, long M) {
		if(m == 0)
			return M;
		return GCFmm(M % m, m);
	}
	public static BigInteger answer(int A, int B) {
		BigInteger ls = BigInteger.ZERO, lc = BigInteger.ZERO, bb = new BigInteger(Integer.toString(B)), b2 = new BigInteger("2"), c[] = new BigInteger[A], d[][] = new BigInteger[A][A];
		for(int i = 1; i <= A; i++) {
			boolean a[] = new boolean[A + 1];
			c[i - 1] = BigInteger.ZERO;
			d[i - 1] = new BigInteger[A];
			List<Long> l = new ArrayList<Long>();
			List<Boolean> s = new ArrayList<Boolean>();
			BigInteger bi = new BigInteger(Integer.toString(i)), bip = new BigInteger(Integer.toString(i - 1));
			for(int j = i; j <= A; j++) {
				if(a[j])
					continue;
				int ni = l.size();
				BigInteger bj = new BigInteger(Integer.toString(j)), n = bi.multiply(bb).divide(bj), np = bip.multiply(bb).divide(bj);
				d[i - 1][j - 1] = bj.multiply(n.multiply(n.add(BigInteger.ONE)).subtract(np.multiply(np.add(BigInteger.ONE)))).divide(b2);
				c[i - 1] = c[i - 1].add(n.subtract(np));
				l.add((long)j);
				s.add(true);
				for(int k = 0; k < ni; k++) {
					long pn = l.get(k), cn = LCM(j, pn);
					BigInteger bcn = new BigInteger(Long.toString(cn));
					boolean ps = s.get(k), cs = !ps;
					n = bi.multiply(bb).divide(bcn);
					np = bip.multiply(bb).divide(bcn);
					BigInteger v = bcn.multiply(n.multiply(n.add(BigInteger.ONE)).subtract(np.multiply(np.add(BigInteger.ONE)))).divide(b2);
					if(cs) {
						d[i - 1][j - 1] = d[i - 1][j - 1].add(v);
						c[i - 1] = c[i - 1].add(n.subtract(np));
					} else {
						d[i - 1][j - 1] = d[i - 1][j - 1].subtract(v);
						c[i - 1] = c[i - 1].subtract(n.subtract(np));
					}
					l.add(cn);
					s.add(cs);
				}
				for(int k = j; k <= A; k += j)
					a[k] = true;
				ls = ls.add(d[i - 1][j - 1]);
			}
			lc = lc.add(c[i - 1]);
		}
		int C = (int)Math.pow(2, numBits(A)), X = B / C * C, U = B % C, ji = X == 0 ? 1 : 0;
		BigInteger rc = BigInteger.ZERO, rs = new BigInteger(Integer.toString(X)).multiply(new BigInteger(Integer.toString(X - 1))).divide(b2);
		Set<Integer> rl = new HashSet<Integer>();
		for(int i = 1; i <= A; i++)
			for(int j = ji; j <= U; j++)
				rl.add(i ^ j);
		for(int k : rl)
			rs = rs.add(new BigInteger(Integer.toString(X + k)));
		if(X <= 0 || A >= 2 && B >= 3 || A >= 3 && B >= 2)
			rc = new BigInteger(Integer.toString(X + rl.size()));
		else {
			rs = rs.subtract(BigInteger.ONE);
			rc = new BigInteger(Integer.toString(X + rl.size() - 1));
		}
//		System.out.println("c: " + Arrays.toString(c));
//		System.out.println("s: " + Arrays.toString(d[16]));
//		System.out.println("sa: " + ls + ", sb: " + rs);
//		System.out.println("ca: " + lc + ", cb: " + rc);
		return ls.multiply(rc).multiply(new BigInteger(Integer.toString((int)Math.pow(10, numDigs(B))))).add(rs.multiply(lc));
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt(), B = in.nextInt();
		System.out.println(answer(A, B));
	}
}
